package com.grace.portal.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.grace.portal.dao.UserDao;
import com.grace.portal.entity.User;
import com.grace.portal.service.UserService;
import com.grace.project.common.jpa.Filter;
import com.grace.project.common.jpa.Filter.Operator;

@Service("userServiceImpl")
public class UserServiceImpl extends BaseServiceImpl<User, Long> implements UserService{

	@Resource(name = "userDaoImpl")
	private UserDao userDao;
	
	public User Login(String userName,String password){
		if(StringUtils.isBlank(userName) || StringUtils.isBlank(password)){
			return null;
		}
		User user = null;
		List<Filter> filters = new ArrayList<Filter>();
		Filter userNamefilter = new Filter("userName",Operator.eq,userName);
		Filter passWordfilter = new Filter("password",Operator.eq,password);
		filters.add(userNamefilter);
		filters.add(passWordfilter);
		List<User> userList = userDao.findList(0, 1, filters, null);
		if(userList != null && userList.size() > 0){
			user = userList.get(0);
		}
		return user;
	}
}
